<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns the latest global transaction ID</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ref.mysqlnd-ms.html">Mysqlnd_ms 函数</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mysqlnd-ms-get-last-used-connection.html">mysqlnd_ms_get_last_used_connection</a></div>
 <div class="up"><a href="ref.mysqlnd-ms.html">Mysqlnd_ms 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.mysqlnd-ms-get-last-gtid" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysqlnd_ms_get_last_gtid</h1>
  <p class="verinfo">(PECL mysqlnd_ms &gt;= 1.2.0)</p><p class="refpurpose"><span class="refname">mysqlnd_ms_get_last_gtid</span> &mdash; <span class="dc-title">Returns the latest global transaction ID</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.mysqlnd-ms-get-last-gtid-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> 
   <span class="methodname"><strong>mysqlnd_ms_get_last_gtid</strong></span>
    ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$connection</code></span>
   )</div>

  <p class="para rdfs-comment">
   Returns a global transaction identifier which belongs to a write operation no
   older than the last write performed by the client. It is not guaranteed that
   the global transaction identifier is identical to that one created for the
   last write transaction performed by the client.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mysqlnd-ms-get-last-gtid-parameters">
  <h3 class="title">参数</h3>
  <dl>

   
    <dt>
<em><code class="parameter">connection</code></em></dt>

    <dd>

     <p class="para">
      A PECL/mysqlnd_ms connection handle to a MySQL server of the type
      <a href="ref.pdo-mysql.html" class="link">PDO_MYSQL</a>, <a href="book.mysqli.html" class="link">mysqli</a>&gt; or
      <a href="book.mysql.html" class="link">ext/mysql</a>.
      The connection handle is obtained when opening a connection with
      a host name that matches a mysqlnd_ms configuration file
      entry using any of the above three MySQL driver extensions.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mysqlnd-ms-get-last-gtid-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a global transaction ID (GTID) on success.
   Otherwise, returns <strong><code>FALSE</code></strong>.
  </p>
  <p class="para">
   The function <span class="function"><strong>mysqlnd_ms_get_last_gtid()</strong></span> returns the
   GTID obtained when executing the SQL statement from
   the <em>fetch_last_gtid</em> entry of the
   <em>global_transaction_id_injection</em> section from
   the plugins configuration file.
  </p>
  <p class="para">
   The function may be called after the GTID has been incremented.
  </p>
 </div>


 <div class="refsect1 unknown-returnvaluet" id="refsect1-function.mysqlnd-ms-get-last-gtid-unknown-returnvaluet">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    <span class="function"><strong>mysqlnd_ms_get_last_gtid()</strong></span> requires
    PHP &gt;= 5.4.0 and PECL mysqlnd_ms &gt;= 1.2.0. Internally, it is using
    a <em>mysqlnd</em> library C functionality not available with PHP 5.3.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mysqlnd-ms-get-last-gtid-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1809">
    <p><strong>Example #1 <span class="function"><strong>mysqlnd_ms_get_last_gtid()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Open&nbsp;mysqlnd_ms&nbsp;connection&nbsp;using&nbsp;mysqli,&nbsp;PDO_MySQL&nbsp;or&nbsp;mysql&nbsp;extension&nbsp;*/<br /></span><span style="color: #0000BB">$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"myapp"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"database"</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">)<br />&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;Of&nbsp;course,&nbsp;your&nbsp;error&nbsp;handling&nbsp;is&nbsp;nicer...&nbsp;*/<br />&nbsp;&nbsp;</span><span style="color: #007700">die(</span><span style="color: #0000BB">sprintf</span><span style="color: #007700">(</span><span style="color: #DD0000">"[%d]&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mysqli_connect_errno</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">mysqli_connect_error</span><span style="color: #007700">()));<br /><br /></span><span style="color: #FF8000">/*&nbsp;auto&nbsp;commit&nbsp;mode,&nbsp;transaction&nbsp;on&nbsp;master,&nbsp;GTID&nbsp;must&nbsp;be&nbsp;incremented&nbsp;*/<br /></span><span style="color: #007700">if&nbsp;(!</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"DROP&nbsp;TABLE&nbsp;IF&nbsp;EXISTS&nbsp;test"</span><span style="color: #007700">))<br />&nbsp;&nbsp;die(</span><span style="color: #0000BB">sprintf</span><span style="color: #007700">(</span><span style="color: #DD0000">"[%d]&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">errno</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">error</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"GTID&nbsp;after&nbsp;transaction&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mysqlnd_ms_get_last_gtid</span><span style="color: #007700">(</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">/*&nbsp;auto&nbsp;commit&nbsp;mode,&nbsp;transaction&nbsp;on&nbsp;master,&nbsp;GTID&nbsp;must&nbsp;be&nbsp;incremented&nbsp;*/<br /></span><span style="color: #007700">if&nbsp;(!</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"CREATE&nbsp;TABLE&nbsp;test(id&nbsp;INT)"</span><span style="color: #007700">))<br />&nbsp;&nbsp;die(</span><span style="color: #0000BB">sprintf</span><span style="color: #007700">(</span><span style="color: #DD0000">"[%d]&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">errno</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">error</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"GTID&nbsp;after&nbsp;transaction&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mysqlnd_ms_get_last_gtid</span><span style="color: #007700">(</span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mysqlnd-ms-get-last-gtid-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member">
     <a href="mysqlnd-ms.gtid.html" class="link">Global Transaction IDs</a>
    </li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ref.mysqlnd-ms.html">Mysqlnd_ms 函数</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mysqlnd-ms-get-last-used-connection.html">mysqlnd_ms_get_last_used_connection</a></div>
 <div class="up"><a href="ref.mysqlnd-ms.html">Mysqlnd_ms 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
